import type { BlueToothVersion, DuiBi, GPRS_FORM, UpdateData, UpdateRecord } from './page'
import { UpdateType } from './page'
import documentApi from '@/api/modules/document'
import type { EnumOption } from '@/api/modules/types/document'

export function useGprsVersionForm() {
  const versionFormData = reactive<GPRS_FORM>(getForm())
  function getForm(): GPRS_FORM {
    return {
      SoftVer: '',
      SoftDate: '',
      HardVer: '',
      HardDate: '',
      ICCID: '',
      SIM: '',
      ConnCurStatus: 0,
      ConnLastSuccTime: '',
      ConnLastFailTime: '',
      ConnCurStatusName: '',
      Signal: 0,
      IMEI: '',
    }
  }
  const initForm = () => {
    Object.assign(versionFormData, getForm())
  }
  return { versionFormData, initForm }
}

export function useDuiBiForm() {
  const formData = ref<DuiBi>(getForm())
  function getForm(): DuiBi {
    return {
      TAIn: 0,
      TAOut: 0,
      TVIn: 0,
      TVOut: 0,
      WingWay: 0,
    }
  }

  function initForm() {
    formData.value = getForm()
  }
  return { formData, initForm }
}

export function useEnumInfos() {
  const enumInfos = ref<EnumOption[]>([])
  documentApi.GetEnumInfos({ type: 'DIM.GYHR.WiringWayOptions' }).then((res) => {
    enumInfos.value = res
  })

  return enumInfos
}

export function useUpdateRecordForm() {
  const updateFormData = ref<UpdateRecord>(getForm())
  function getForm(): UpdateRecord {
    return {
      UpCurStatus: 0,
      UpLastBeginTime: '',
      UpLastEndTime: '',
      UpBefourVer: '',
      UpEndVer: '',
    }
  }
  function initForm() {
    updateFormData.value = getForm()
  }
  return { updateFormData, initForm }
}

export function useUpdateDataForm(deviceId: string) {
  const updateDataFormData = reactive<UpdateData>(getForm())
  function getForm(): UpdateData {
    return {
      deviceObjID: deviceId,
      upgradeType: UpdateType.FTP,
      url: '',
      upUser: '',
      upPasswd: '',
    }
  }
  function initForm() {
    Object.assign(updateDataFormData, getForm())
  }

  return { updateDataFormData, initForm }
}

export function useBlueToothForm() {
  const blueToothFormData = ref<BlueToothVersion>(getForm())
  function getForm(): BlueToothVersion {
    return {
      SoftVer: '',
      SoftDate: '',
      HardVer: '',
      HardDate: '',
      ConnCurStatus: 0,
    }
  }
  function initForm() {
    blueToothFormData.value = getForm()
  }
  return { blueToothFormData, initForm }
}
